﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace xxxy.DAL
{
	/// <summary>
	/// 数据访问类:userInfo
	/// </summary>
	public partial class userInfo
	{
		public userInfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("userID", "userInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int userID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from userInfo");
			strSql.Append(" where userID=@userID");
			SqlParameter[] parameters = {
					new SqlParameter("@userID", SqlDbType.Int,4)
			};
			parameters[0].Value = userID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(xxxy.Model.userInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into userInfo(");
			strSql.Append("userNum,userName,usex,userPwd,useridnumber,ubanknumber,uphone,utel,uemail,uqq,udegree1,uxuwei1,umajor1,uschool1,ugratime1,udegree2,uxuwei2,umajor2,uschool2,ugratime2,uposition,utitle,ujobtime,uiscomputer,userRemarks,userLevel)");
			strSql.Append(" values (");
			strSql.Append("@userNum,@userName,@usex,@userPwd,@useridnumber,@ubanknumber,@uphone,@utel,@uemail,@uqq,@udegree1,@uxuwei1,@umajor1,@uschool1,@ugratime1,@udegree2,@uxuwei2,@umajor2,@uschool2,@ugratime2,@uposition,@utitle,@ujobtime,@uiscomputer,@userRemarks,@userLevel)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@userNum", SqlDbType.Char,10),
					new SqlParameter("@userName", SqlDbType.VarChar,10),
					new SqlParameter("@usex", SqlDbType.Char,2),
					new SqlParameter("@userPwd", SqlDbType.VarChar,15),
					new SqlParameter("@useridnumber", SqlDbType.Char,18),
					new SqlParameter("@ubanknumber", SqlDbType.VarChar,20),
					new SqlParameter("@uphone", SqlDbType.VarChar,11),
					new SqlParameter("@utel", SqlDbType.VarChar,12),
					new SqlParameter("@uemail", SqlDbType.NVarChar,50),
					new SqlParameter("@uqq", SqlDbType.NVarChar,15),
					new SqlParameter("@udegree1", SqlDbType.NVarChar,50),
					new SqlParameter("@uxuwei1", SqlDbType.NVarChar,50),
					new SqlParameter("@umajor1", SqlDbType.NVarChar,50),
					new SqlParameter("@uschool1", SqlDbType.NVarChar,50),
					new SqlParameter("@ugratime1", SqlDbType.Date,3),
					new SqlParameter("@udegree2", SqlDbType.NVarChar,50),
					new SqlParameter("@uxuwei2", SqlDbType.NVarChar,50),
					new SqlParameter("@umajor2", SqlDbType.NVarChar,50),
					new SqlParameter("@uschool2", SqlDbType.NVarChar,50),
					new SqlParameter("@ugratime2", SqlDbType.Date,3),
					new SqlParameter("@uposition", SqlDbType.NVarChar,20),
					new SqlParameter("@utitle", SqlDbType.NVarChar,10),
					new SqlParameter("@ujobtime", SqlDbType.Date,3),
					new SqlParameter("@uiscomputer", SqlDbType.Int,4),
					new SqlParameter("@userRemarks", SqlDbType.VarChar,100),
					new SqlParameter("@userLevel", SqlDbType.Int,4)};
			parameters[0].Value = model.userNum;
			parameters[1].Value = model.userName;
			parameters[2].Value = model.usex;
			parameters[3].Value = model.userPwd;
			parameters[4].Value = model.useridnumber;
			parameters[5].Value = model.ubanknumber;
			parameters[6].Value = model.uphone;
			parameters[7].Value = model.utel;
			parameters[8].Value = model.uemail;
			parameters[9].Value = model.uqq;
			parameters[10].Value = model.udegree1;
			parameters[11].Value = model.uxuwei1;
			parameters[12].Value = model.umajor1;
			parameters[13].Value = model.uschool1;
			parameters[14].Value = model.ugratime1;
			parameters[15].Value = model.udegree2;
			parameters[16].Value = model.uxuwei2;
			parameters[17].Value = model.umajor2;
			parameters[18].Value = model.uschool2;
			parameters[19].Value = model.ugratime2;
			parameters[20].Value = model.uposition;
			parameters[21].Value = model.utitle;
			parameters[22].Value = model.ujobtime;
			parameters[23].Value = model.uiscomputer;
			parameters[24].Value = model.userRemarks;
			parameters[25].Value = model.userLevel;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(xxxy.Model.userInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update userInfo set ");
			strSql.Append("userNum=@userNum,");
			strSql.Append("userName=@userName,");
			strSql.Append("usex=@usex,");
			strSql.Append("userPwd=@userPwd,");
			strSql.Append("useridnumber=@useridnumber,");
			strSql.Append("ubanknumber=@ubanknumber,");
			strSql.Append("uphone=@uphone,");
			strSql.Append("utel=@utel,");
			strSql.Append("uemail=@uemail,");
			strSql.Append("uqq=@uqq,");
			strSql.Append("udegree1=@udegree1,");
			strSql.Append("uxuwei1=@uxuwei1,");
			strSql.Append("umajor1=@umajor1,");
			strSql.Append("uschool1=@uschool1,");
			strSql.Append("ugratime1=@ugratime1,");
			strSql.Append("udegree2=@udegree2,");
			strSql.Append("uxuwei2=@uxuwei2,");
			strSql.Append("umajor2=@umajor2,");
			strSql.Append("uschool2=@uschool2,");
			strSql.Append("ugratime2=@ugratime2,");
			strSql.Append("uposition=@uposition,");
			strSql.Append("utitle=@utitle,");
			strSql.Append("ujobtime=@ujobtime,");
			strSql.Append("uiscomputer=@uiscomputer,");
			strSql.Append("userRemarks=@userRemarks,");
			strSql.Append("userLevel=@userLevel");
			strSql.Append(" where userID=@userID");
			SqlParameter[] parameters = {
					new SqlParameter("@userNum", SqlDbType.Char,10),
					new SqlParameter("@userName", SqlDbType.VarChar,10),
					new SqlParameter("@usex", SqlDbType.Char,2),
					new SqlParameter("@userPwd", SqlDbType.VarChar,15),
					new SqlParameter("@useridnumber", SqlDbType.Char,18),
					new SqlParameter("@ubanknumber", SqlDbType.VarChar,20),
					new SqlParameter("@uphone", SqlDbType.VarChar,11),
					new SqlParameter("@utel", SqlDbType.VarChar,12),
					new SqlParameter("@uemail", SqlDbType.NVarChar,50),
					new SqlParameter("@uqq", SqlDbType.NVarChar,15),
					new SqlParameter("@udegree1", SqlDbType.NVarChar,50),
					new SqlParameter("@uxuwei1", SqlDbType.NVarChar,50),
					new SqlParameter("@umajor1", SqlDbType.NVarChar,50),
					new SqlParameter("@uschool1", SqlDbType.NVarChar,50),
					new SqlParameter("@ugratime1", SqlDbType.Date,3),
					new SqlParameter("@udegree2", SqlDbType.NVarChar,50),
					new SqlParameter("@uxuwei2", SqlDbType.NVarChar,50),
					new SqlParameter("@umajor2", SqlDbType.NVarChar,50),
					new SqlParameter("@uschool2", SqlDbType.NVarChar,50),
					new SqlParameter("@ugratime2", SqlDbType.Date,3),
					new SqlParameter("@uposition", SqlDbType.NVarChar,20),
					new SqlParameter("@utitle", SqlDbType.NVarChar,10),
					new SqlParameter("@ujobtime", SqlDbType.Date,3),
					new SqlParameter("@uiscomputer", SqlDbType.Int,4),
					new SqlParameter("@userRemarks", SqlDbType.VarChar,100),
					new SqlParameter("@userLevel", SqlDbType.Int,4),
					new SqlParameter("@userID", SqlDbType.Int,4)};
			parameters[0].Value = model.userNum;
			parameters[1].Value = model.userName;
			parameters[2].Value = model.usex;
			parameters[3].Value = model.userPwd;
			parameters[4].Value = model.useridnumber;
			parameters[5].Value = model.ubanknumber;
			parameters[6].Value = model.uphone;
			parameters[7].Value = model.utel;
			parameters[8].Value = model.uemail;
			parameters[9].Value = model.uqq;
			parameters[10].Value = model.udegree1;
			parameters[11].Value = model.uxuwei1;
			parameters[12].Value = model.umajor1;
			parameters[13].Value = model.uschool1;
			parameters[14].Value = model.ugratime1;
			parameters[15].Value = model.udegree2;
			parameters[16].Value = model.uxuwei2;
			parameters[17].Value = model.umajor2;
			parameters[18].Value = model.uschool2;
			parameters[19].Value = model.ugratime2;
			parameters[20].Value = model.uposition;
			parameters[21].Value = model.utitle;
			parameters[22].Value = model.ujobtime;
			parameters[23].Value = model.uiscomputer;
			parameters[24].Value = model.userRemarks;
			parameters[25].Value = model.userLevel;
			parameters[26].Value = model.userID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int userID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from userInfo ");
			strSql.Append(" where userID=@userID");
			SqlParameter[] parameters = {
					new SqlParameter("@userID", SqlDbType.Int,4)
			};
			parameters[0].Value = userID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string userIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from userInfo ");
			strSql.Append(" where userID in ("+userIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public xxxy.Model.userInfo GetModel(int userID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 userID,userNum,userName,usex,userPwd,useridnumber,ubanknumber,uphone,utel,uemail,uqq,udegree1,uxuwei1,umajor1,uschool1,ugratime1,udegree2,uxuwei2,umajor2,uschool2,ugratime2,uposition,utitle,ujobtime,uiscomputer,userRemarks,userLevel from userInfo ");
			strSql.Append(" where userID=@userID");
			SqlParameter[] parameters = {
					new SqlParameter("@userID", SqlDbType.Int,4)
			};
			parameters[0].Value = userID;

			xxxy.Model.userInfo model=new xxxy.Model.userInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public xxxy.Model.userInfo DataRowToModel(DataRow row)
		{
			xxxy.Model.userInfo model=new xxxy.Model.userInfo();
			if (row != null)
			{
				if(row["userID"]!=null && row["userID"].ToString()!="")
				{
					model.userID=int.Parse(row["userID"].ToString());
				}
				if(row["userNum"]!=null)
				{
					model.userNum=row["userNum"].ToString();
				}
				if(row["userName"]!=null)
				{
					model.userName=row["userName"].ToString();
				}
				if(row["usex"]!=null)
				{
					model.usex=row["usex"].ToString();
				}
				if(row["userPwd"]!=null)
				{
					model.userPwd=row["userPwd"].ToString();
				}
				if(row["useridnumber"]!=null)
				{
					model.useridnumber=row["useridnumber"].ToString();
				}
				if(row["ubanknumber"]!=null)
				{
					model.ubanknumber=row["ubanknumber"].ToString();
				}
				if(row["uphone"]!=null)
				{
					model.uphone=row["uphone"].ToString();
				}
				if(row["utel"]!=null)
				{
					model.utel=row["utel"].ToString();
				}
				if(row["uemail"]!=null)
				{
					model.uemail=row["uemail"].ToString();
				}
				if(row["uqq"]!=null)
				{
					model.uqq=row["uqq"].ToString();
				}
				if(row["udegree1"]!=null)
				{
					model.udegree1=row["udegree1"].ToString();
				}
				if(row["uxuwei1"]!=null)
				{
					model.uxuwei1=row["uxuwei1"].ToString();
				}
				if(row["umajor1"]!=null)
				{
					model.umajor1=row["umajor1"].ToString();
				}
				if(row["uschool1"]!=null)
				{
					model.uschool1=row["uschool1"].ToString();
				}
				if(row["ugratime1"]!=null && row["ugratime1"].ToString()!="")
				{
					model.ugratime1=DateTime.Parse(row["ugratime1"].ToString());
				}
				if(row["udegree2"]!=null)
				{
					model.udegree2=row["udegree2"].ToString();
				}
				if(row["uxuwei2"]!=null)
				{
					model.uxuwei2=row["uxuwei2"].ToString();
				}
				if(row["umajor2"]!=null)
				{
					model.umajor2=row["umajor2"].ToString();
				}
				if(row["uschool2"]!=null)
				{
					model.uschool2=row["uschool2"].ToString();
				}
				if(row["ugratime2"]!=null && row["ugratime2"].ToString()!="")
				{
					model.ugratime2=DateTime.Parse(row["ugratime2"].ToString());
				}
				if(row["uposition"]!=null)
				{
					model.uposition=row["uposition"].ToString();
				}
				if(row["utitle"]!=null)
				{
					model.utitle=row["utitle"].ToString();
				}
				if(row["ujobtime"]!=null && row["ujobtime"].ToString()!="")
				{
					model.ujobtime=DateTime.Parse(row["ujobtime"].ToString());
				}
				if(row["uiscomputer"]!=null && row["uiscomputer"].ToString()!="")
				{
					model.uiscomputer=int.Parse(row["uiscomputer"].ToString());
				}
				if(row["userRemarks"]!=null)
				{
					model.userRemarks=row["userRemarks"].ToString();
				}
				if(row["userLevel"]!=null && row["userLevel"].ToString()!="")
				{
					model.userLevel=int.Parse(row["userLevel"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select userID,userNum,userName,usex,userPwd,useridnumber,ubanknumber,uphone,utel,uemail,uqq,udegree1,uxuwei1,umajor1,uschool1,ugratime1,udegree2,uxuwei2,umajor2,uschool2,ugratime2,uposition,utitle,ujobtime,uiscomputer,userRemarks,userLevel ");
			strSql.Append(" FROM userInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" userID,userNum,userName,usex,userPwd,useridnumber,ubanknumber,uphone,utel,uemail,uqq,udegree1,uxuwei1,umajor1,uschool1,ugratime1,udegree2,uxuwei2,umajor2,uschool2,ugratime2,uposition,utitle,ujobtime,uiscomputer,userRemarks,userLevel ");
			strSql.Append(" FROM userInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM userInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.userID desc");
			}
			strSql.Append(")AS Row, T.*  from userInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "userInfo";
			parameters[1].Value = "userID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

